/*
 * 官方函数
 */
function zy_selectmenu(id){
    var sl = document.getElementById(id);
    if (sl) {
        var sp = sl.parentElement; //<span>
        if (sp) {
            var ch = sp.getElementsByTagName("div")[0];
            var t = sl.options[sl.selectedIndex].text;
            if (ch) {
                ch.innerHTML = t;
            }
        }
    }
}

function zy_for(e, cb){
	var ch;
	if(e.currentTarget)
    	ch = e.currentTarget.previousElementSibling;
	else
		ch = e.previousElementSibling;
    if (ch.nodeName == "INPUT") {
        if (ch.type == "checkbox") 
            ch.checked = !ch.checked;
        if (ch.type == "radio" && !ch.checked) 
            ch.checked = "checked";
        
    }
    if (cb) 
        cb(e, ch.checked);
}


function zy_fold(e, col){
    var a = e.currentTarget.nextElementSibling;
    if (a.nodeName == "DIV") {
        if (col) 
            a.className = a.className.replace("col-c", "");
        else 
            a.className += ' col-c';
    }
}

function zy_touch(c, f){
    var t = event.currentTarget;
	if(!t.zTouch) {
        t.zTouch = new zyClick(t, f, c); 
		t.zTouch._touchStart(event);
    }
}

function zy_parse(){
    var params = {};
    var loc = String(document.location);
    if (loc.indexOf("?") > 0) 
        loc = loc.substr(loc.indexOf('?') + 1);
    else 
        loc = uexWindow.getUrlQuery();
    var pieces = loc.split('&');
    params.keys = [];
    for (var i = 0; i < pieces.length; i += 1) {
        var keyVal = pieces[i].split('=');
        params[keyVal[0]] = decodeURIComponent(keyVal[1]);
        params.keys.push(keyVal[0]);
    }
    return params;
}

function $$(id)
{
	return document.getElementById(id);
}
function int(s)
{
	return parseInt(s);
}

function zy_con(id,url,x,y)
{
	var s=window.getComputedStyle($$(id),null);
	uexWindow.openPopover(id,"0",url,"",int(x),int(y),int(s.width),int(s.height),int(s.fontSize),"0");
}
function zy_resize(id,x,y)
{
	var s=window.getComputedStyle($$(id),null);
	uexWindow.setPopoverFrame(id,int(x),int(y),int(s.width),int(s.height));	
}

function zy_init()
{
	if(window.navigator.platform=="Win32")
		document.body.style.fontSize=window.localStorage["defaultfontsize"];
}
function zy_cc(t){
    if (!t.cancelClick) {
        t.cancelClick = true;
        t.addEventListener("click", function(){
            event.stopPropagation();
        }, true);
    }
}


/*
 * 自定义函数
 */
function getLocation(){	
	uexLocation.openLocation();
	uexLocation.onChange=function(inLat,inLog){
		uexLocation.closeLocation();
		localStorage['lng']=inLog;
		localStorage['lat']=inLat;
	}
}

function Trim(str){return str.replace(/(^\s*)|(\s*$)/g, "")}
function LTrim(str){return str.replace(/(^\s*)/g,  "")}
function RTrim(str){return str.replace(/(\s*$)/g,  "")}
function AllTrim(str){return str.replace(/\s*/g,'')}
function substr(str, len){
	if( ! str || ! len){
			return '';
		}
		var a = 0;
		var i = 0;
		var temp = '';
		for (i = 0; i < str.length; i ++ ){
			if (str.charCodeAt(i) > 255){
		 	a += 2;
			}else{
 			a ++ ;
			}
			if(a > len){
 			return temp;
			}
			temp += str.charAt(i);
		}
		return str;
}

function Now(){
	var myDate = new Date()
	return myDate.getFullYear()+'-'+(myDate.getMonth()+1)+'-'+(myDate.getDate()<10?'0':'')+myDate.getDate()+' '+(myDate.getHours()<10?'0':'')+myDate.getHours()+':'+(myDate.getMinutes()<10?'0':'')+myDate.getMinutes()+':'+(myDate.getSeconds()<10?'0':'')+myDate.getSeconds();
}

/*
 * 调用外部浏览器
 */
function loadLink(url){
	var appInfo = ''; 
	var filter = '';
	var dataInfo = url;
	if(localStorage['device']==1){
		appInfo = 'android.intent.action.VIEW';
		filter = 'text/html';
	}
	uexWidget.loadApp(appInfo, filter, dataInfo);
}

/*
 * 幻灯片
 */
var em_focus=1;
function zy_Switch(t,i){
	var Switch=$$('switch'),Em=Switch.getElementsByTagName('em');
	if(typeof(i)!='undefined'){
		em_focus=i;
	}
	Switch.querySelector('.focus').className ='';
	if(em_focus==Em.length){
		em_focus=0;
	}
	Em[em_focus].className='focus';
	t.moveToPoint(em_focus);
	em_focus++;
}

function zy_slide(){
    var switchTime;
	$$('slider').slide=new zySlide(
		'slider',
		'H',
		function(){
			window.clearInterval(switchTime);
			zy_Switch(this,this.currentPoint);
			var t=this;
			switchTime=window.setInterval(function(){zy_Switch(t);},5000);
		},
		false,
		function(e){
		}
	);
	switchTime=window.setInterval(function(){zy_Switch($$('slider').slide);},5000);
}